import request from '../utils/request'

/**
 * API 接口定义
 */

// 用户相关接口
export const userApi = {
  // 登录
  login: (data: { username: string; password: string }) =>
    request.post('/auth/login', data),
    
  // 注册
  register: (data: { username: string; password: string; email?: string }) =>
    request.post('/auth/register', data),
    
  // 获取用户信息
  getProfile: () =>
    request.get('/user/profile'),
    
  // 更新用户信息
  updateProfile: (data: any) =>
    request.put('/user/profile', data),
    
  // 上传头像
  uploadAvatar: (filePath: string) =>
    request.upload('/user/avatar', filePath),
    
  // 修改密码
  changePassword: (data: { oldPassword: string; newPassword: string }) =>
    request.post('/user/change-password', data),
    
  // 重置密码
  resetPassword: (data: { email: string }) =>
    request.post('/auth/reset-password', data),
}

// 应用相关接口
export const appApi = {
  // 获取应用配置
  getConfig: () =>
    request.get('/app/config'),
    
  // 检查更新
  checkUpdate: () =>
    request.get('/app/check-update'),
    
  // 获取公告
  getNotices: (params?: { page?: number; size?: number }) =>
    request.get('/app/notices', { params }),
    
  // 意见反馈
  feedback: (data: { content: string; contact?: string; images?: string[] }) =>
    request.post('/app/feedback', data),
}

// 文件相关接口
export const fileApi = {
  // 上传文件
  upload: (filePath: string, type?: string) =>
    request.upload(`/file/upload${type ? `?type=${type}` : ''}`, filePath),
    
  // 删除文件
  delete: (fileId: string) =>
    request.delete(`/file/${fileId}`),
    
  // 获取文件信息
  getInfo: (fileId: string) =>
    request.get(`/file/${fileId}`),
}

// 示例业务接口
export const businessApi = {
  // 获取列表数据
  getList: (params: { page: number; size: number; keyword?: string }) =>
    request.get('/business/list', { params }),
    
  // 获取详情
  getDetail: (id: string) =>
    request.get(`/business/${id}`),
    
  // 创建数据
  create: (data: any) =>
    request.post('/business', data),
    
  // 更新数据
  update: (id: string, data: any) =>
    request.put(`/business/${id}`, data),
    
  // 删除数据
  delete: (id: string) =>
    request.delete(`/business/${id}`),
}

export default {
  userApi,
  appApi,
  fileApi,
  businessApi
}
